//
//  NextInviteViewController.m
//  LoveAttention
//
//  Created by 鞠超 on 15/12/31.
//  Copyright © 2015年 JC. All rights reserved.
//

#import "NextInviteViewController.h"
#import "DataProvider.h"
#import "SVProgressHUD.h"
#import "Invite_Model.h"
#import "UIImageView+WebCache.h"
@interface NextInviteViewController ()

@property (nonatomic, strong) UIImageView * image;

@property (nonatomic, strong) UILabel * name;

@property (nonatomic, strong) UIImageView * sex;

@property (nonatomic, strong) UILabel * age;

@property (nonatomic, strong) UILabel * address;

@property (nonatomic, strong) UILabel * time;

@property (nonatomic, strong) UILabel * detail;

@property (nonatomic, strong) UILabel * qq;

@property (nonatomic, strong) UILabel * weixin;

@property (nonatomic, strong) UILabel * tel;

@property (nonatomic, strong) UILabel * date;

//数据
@property (nonatomic, strong) NSMutableArray * arr_data;

@property (nonatomic, strong) UIScrollView * scrollView;
@end

@implementation NextInviteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navigationController];
    
    [self p_setupView];
    
    [self p_data];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - navigationController
- (void)p_navigationController
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.navigationItem.title = @"我的邀请人资料";
    UIButton * btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [btn setBackgroundImage:[UIImage imageNamed:@"返回"] forState:(UIControlStateNormal)];
        btn.frame = CGRectMake(10, 20, 25, 30);
    [btn addTarget:self action:@selector(leftBarButtonItemAction:) forControlEvents:(UIControlEventTouchUpInside)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    
}
//点击事件(左)
- (void)leftBarButtonItemAction:(UIBarButtonItem *)bar
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 布局
- (void)p_setupView
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    self.scrollView.contentSize = CGSizeMake(0, self.view.frame.size.height + 1);
    [self.view addSubview:self.scrollView];
    
    
    UIImageView * view_bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width , 105)];
    view_bg.image = [UIImage imageNamed:@"头像背景1"];
    view_bg.alpha = 1;
    [self.scrollView addSubview:view_bg];
    
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, 60, 60)];
    self.image.image = [UIImage imageNamed:@"头像"];
    self.image.layer.cornerRadius = 30;
    [view_bg addSubview:self.image];
    
    self.name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image.frame) + 10, CGRectGetMinY(self.image.frame), 200, 22)];
    self.name.text = @"李晓明李小双";
    self.name.textColor = [UIColor whiteColor];
    [view_bg addSubview:self.name];
    
    self.sex = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image.frame) + 10, CGRectGetMaxY(self.name.frame) + 15, 25, 25)];
    self.sex.image = [UIImage imageNamed:@"nvshengfuhao"];
    [view_bg addSubview:self.sex];
    
    self.age = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.sex.frame) + 10, CGRectGetMaxY(self.name.frame) + 15, 40, 25)];
    self.age.text = @"23岁";
    self.age.textColor = [UIColor whiteColor];
    [view_bg addSubview:self.age];

    self.address = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.age.frame) + 10, CGRectGetMaxY(self.name.frame) + 15, 150, 25)];
    self.address.text = @"山东临沂";
//    self.address.backgroundColor = [UIColor orangeColor];
    self.address.textColor = [UIColor whiteColor];
    [view_bg addSubview:self.address];

    self.time = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 15 - 150, CGRectGetMinY(self.name.frame) - 20, 150, 17)];
//    self.time.backgroundColor = [UIColor orangeColor];
    self.time.font = [UIFont systemFontOfSize:13];
    self.time.text = @"注册时间 2015-09-09";
    self.time.textColor = [UIColor grayColor];
    self.time.textAlignment = NSTextAlignmentRight;
    [view_bg addSubview:self.time];
    
    UIView * view_detail = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_bg.frame) , self.view.frame.size.width, 40)];
    view_detail.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_detail];
    
    UILabel * label_detail = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 70, 24)];
    label_detail.text = @"个性签名:";
    label_detail.textColor = [UIColor grayColor];
    label_detail.font = [UIFont systemFontOfSize:15];
    [view_detail addSubview:label_detail];
    
    self.detail = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_detail.frame) + 10, 8, 230, 24)];
    self.detail.text = @"开始了解地区将完善的";
    self.detail.textColor = [UIColor grayColor];
    self.detail.font = [UIFont systemFontOfSize:15];
    [view_detail addSubview:self.detail];
    
    
    UIView * view_detail1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_detail.frame) + 10, self.view.frame.size.width, 40)];
    view_detail1.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_detail1];
    
    UILabel * label_detail1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 70, 24)];
    label_detail1.text = @"详细信息";
    label_detail1.textColor = [UIColor grayColor];
    label_detail1.font = [UIFont systemFontOfSize:15];
    [view_detail1 addSubview:label_detail1];
    
    
    UIView * view_qq = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_detail1.frame) + 1, self.view.frame.size.width, 40)];
    view_qq.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_qq];
    
    UILabel * label_qq = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 35, 24)];
    label_qq.text = @"QQ:";
    label_qq.textColor = [UIColor grayColor];
    label_qq.font = [UIFont systemFontOfSize:15];
    [view_qq addSubview:label_qq];
    
    self.qq = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_qq.frame) + 10, 8, 230, 24)];
    self.qq.text = @"1234567890123";
    self.qq.textColor = [UIColor grayColor];
    self.qq.font = [UIFont systemFontOfSize:15];
    [view_qq addSubview:self.qq];
    
    
    UIView * view_weixin = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_qq.frame) + 1, self.view.frame.size.width, 40)];
    view_weixin.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_weixin];
    
    UILabel * label_weixin = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 35, 24)];
    label_weixin.text = @"微信:";
    label_weixin.textColor = [UIColor grayColor];
    label_weixin.font = [UIFont systemFontOfSize:15];
    [view_weixin addSubview:label_weixin];
    
    self.weixin = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_weixin.frame) + 10, 8, 230, 24)];
    self.weixin.text = @"1234567890123";
    self.weixin.textColor = [UIColor grayColor];
    self.weixin.font = [UIFont systemFontOfSize:15];
    [view_weixin addSubview:self.weixin];
    
    UIView * view_tel = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_weixin.frame) + 1, self.view.frame.size.width, 40)];
    view_tel.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_tel];
    
    UILabel * label_tel = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 35, 24)];
    label_tel.text = @"手机:";
    label_tel.textColor = [UIColor grayColor];
    label_tel.font = [UIFont systemFontOfSize:15];
    [view_tel addSubview:label_tel];
    
    self.tel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_tel.frame) + 10, 8, 230, 24)];
    self.tel.text = @"1234567890123";
    self.tel.textColor = [UIColor grayColor];
    self.tel.font = [UIFont systemFontOfSize:15];
    [view_tel addSubview:self.tel];
    
    
    UIView * view_date = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_tel.frame) + 1, self.view.frame.size.width, 40)];
    view_date.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view_date];
    
    UILabel * label_date = [[UILabel alloc] initWithFrame:CGRectMake(20, 8, 35, 24)];
    label_date.text = @"生日:";
    label_date.textColor = [UIColor grayColor];
    label_date.font = [UIFont systemFontOfSize:15];
    [view_date addSubview:label_date];
    
    self.date = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_tel.frame) + 10, 8, 230, 24)];
    self.date.text = @"1234567890123";
    self.date.textColor = [UIColor grayColor];
    self.date.font = [UIFont systemFontOfSize:15];
    [view_date addSubview:self.date];
}

#pragma mark - 加数据
- (void)p_data
{
    DataProvider * dataprovider = [[DataProvider alloc] init];
    [dataprovider setDelegateObject:self setBackFunctionName:@"UserDetail:"];
    
    [dataprovider UserDetailWith:self.memberid];
}

- (void)UserDetail:(id )dict
{
    NSLog(@"%@",dict);
    
    self.arr_data = nil;
    
    if ([dict[@"status"][@"succeed"] intValue] == 1) {
        @try
        {
            Invite_Model * model = [[Invite_Model alloc] init];
            
            [model setValuesForKeysWithDictionary:dict[@"data"]];
            
            [self.arr_data addObject:model];
        }
        @catch (NSException *exception) {
            
        }
        @finally {
            
            Invite_Model * model = self.arr_data.firstObject;
            
            NSString *url = [NSString stringWithFormat:@"%@/upload/%@",Url,model.headportain];
            
            [self.image sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"头像"]];
            
            if(model.name.length == 0)
            {
                self.name.text = [NSString stringWithFormat:@"%@",model.mobile];
            }
            else
            {
                self.name.text = [NSString stringWithFormat:@"%@",model.name];
            }
            
            
            if(model.sex.length == 0)
            {
                self.sex.hidden = YES;
            }
            else
            {
                if([model.sex isEqualToString:@"女"])
                {//女
                    self.sex.image = [UIImage imageNamed:@"nvshengfuhao"];
                }
                else
                {
                    self.sex.image = [UIImage imageNamed:@"nanshengfuhao"];
                }
            }
            
            if(model.intime.length == 0)
            {
                self.time.text = @"注册时间 ";

            }
            else
            {
                NSString * str = [model.intime substringToIndex:10];
                
                self.time.text = [NSString stringWithFormat:@"注册时间 %@",str];
            }
            
            if(model.address.length == 0)
            {
                self.address.text = @"未设置";

            }
            else
            {
                self.address.text = [NSString stringWithFormat:@"%@",model.address];
            }
            
            if(model.qq.length == 0)
            {
                self.qq.text = @"未设置";
            }
            else
            {
                self.qq.text = [NSString stringWithFormat:@"%@",model.qq];
            }
            
            if(model.weixin.length == 0)
            {
                self.weixin.text = @"未设置";
            }
            else
            {
                self.weixin.text = [NSString stringWithFormat:@"%@",model.weixin];
            }
            
            if(model.mobile.length == 0)
            {
                self.tel.text = @"未设置";
            }
            else
            {
                self.tel.text = [NSString stringWithFormat:@"%@",model.mobile];
            }
            
            if(model.birthday.length == 0)
            {
                self.date.text = @"未设置";
            }
            else
            {
                self.date.text = [NSString stringWithFormat:@"%@",model.birthday];
            }
            
            if(model.sign.length == 0)
            {
                self.detail.text = @"未设置";
            }
            else
            {
                self.detail.text = [NSString stringWithFormat:@"%@",model.sign];
            }
            
            if([[NSString stringWithFormat:@"%@",model.age] length] == 0)
            {
                self.age.text = @"未设置";
            }
            else
            {
                self.age.text = [NSString stringWithFormat:@"%@岁",model.age];
            }
            
        }
    }
    else
    {
        [SVProgressHUD showErrorWithStatus:dict[@"status"][@"errdesc"] maskType:SVProgressHUDMaskTypeBlack];
    }
}

#pragma mark - 懒加载
- (NSMutableArray *)arr_data
{
    if(_arr_data == nil)
    {
        self.arr_data = [NSMutableArray array];
    }
    
    return _arr_data;
}



@end
